<template>
	<view class="waterfall-item" @tap="onTap">
		<image @click="todetail(params.id)" v-if="params.defaultImg!=null" :src="params.defaultImg" mode="widthFix" @load="emitHeight" @error="emitHeight"></image>
		<view class="content">
			<view class="" @click="todetail(params.id)">
				<view><view style="color: #1989FA; font-weight:bold; ">#{{params.typeName}}</view><view style="font-weight:bold;letter-spacing:5upx;" >{{params.contentText}}</view></view>
				<view style="margin-top: 28upx;" class="money">
					{{params.nickName.length > 5 ? params.nickName.slice(0, 5)+"..." : params.nickName}}
				</view>
				<view style="margin: 20upx 0 8rpx 0;">
					<!-- <text class="label">{{params.nickName}}</text> -->
					<image class="icon" :src="params.avatarUrl" mode=""></image>
				</view>
			</view>
			
			<view  class="showMessage_fotter">
				<view class="like" @click="like(params.id)">
					<uni-icons color= "#EE0A24" v-show="isLike" type="heart-filled" size="20">
					</uni-icons>
					<uni-icons v-show="!isLike" type="heart" size="20"></uni-icons>
					<text style="position: absolute;">{{num}}</text>
				</view>
				<view class="commit">
					<uni-icons type="chat" size="20"></uni-icons>
					<text style="position: absolute;">{{params.commentNumber}}</text>
				</view>
				<view class="more" @click="collect()">
					<uni-icons v-show="!isCollect" type="star" size="20"></uni-icons>
					<uni-icons color="yellow" v-show="isCollect" type="star-filled" size="20"></uni-icons>
				</view>
			</view>
			
			<!-- <view class="shop-name">{{params.collegeName}}</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		name:"helang-waterfall",
		props:{
			params:{
				type: Object,
				default(){
					return {}
				}
			},
			hasLike:{
				
			},
			tag:{
				type:String | Number,
				default:''
			},
			index:{
				type:Number,
				default:-1
			}
		},
		watch: {
			params: {
				handler: function(newVal, oldVal) {
					this.emitHeight()
					if (newVal) {
						this.isCollect = newVal.haveCollect
						this.isLike = newVal.haveThumb
						this.num = newVal.thumbNum
					}
				},
				immediate: true
			},hasLike: {
				handler: function(newVal, oldVal) {
					console.log(newVal);

				}
			}
			
		},
		data() {
			return {
				isLike:false,
				num:0,
				isCollect: false
			};
		},
		methods:{
			
			todetail(id){
				console.log("aaa");
					uni.navigateTo({
						url: '../../../post-detail?merchantId=' + id
					})
				// uni.navigateTo({

				// 		url:'./detail/detail3?post_id='+id
				// 	})
			},
			//点赞
			like(index){
				console.log(this.params.id);
					this.$request('/post/postThumbUp',{
						postId:this.params.id
					},'GET')
					.then(res=>{
						this.num=this.num+res
						if(res == -1){
							this.isLike = false
						}
						if(res == 1){
							this.isLike = true
						}
							
					}).catch(err=>{
						console.log(err);
					})
			},
			//收藏
			collect(){
				
				console.log(this.params.id);
					this.$request('/post/postCollectUp',{
						postId:this.params.id
					},'GET')
					.then(res=>{
						if(res == -1){
							this.isCollect = false
						}
						if(res == 1){
							this.isCollect = true
						}
							
					}).catch(err=>{
						console.log(err);
					})
			},
			// 发出组件高度信息，在此处可以区分正确和错误的加载，给予错误的提示图片
			emitHeight(e){
				// console.log("2222");
				const query = uni.createSelectorQuery().in(this);
				query.select('.waterfall-item').boundingClientRect(data => {
					let height = Math.floor(data.height);
					// console.log(this.params.title);
					// console.log(this.$props.tag+"高度",height);
					this.$emit("height",height,this.$props.tag);
				}).exec();
			},
			onTap(){
				this.$emit("click",this.$props.index,this.$props.tag);
			}
		}
	}
</script>

<style lang="scss" scoped>
	
.waterfall-item{
	
	.like {
		width: 33%;
	}
	
	.commit {
		margin-left: 50upx;
		width: 33%;
	
	}
	
	.more {
		margin-left: 50upx;
		width: 33%;
	}
	.showMessage_fotter {
		display: flex;
		padding: 10upx 0;
		border-bottom: 0.5px solid #f1f3f4;
		// position: relative;
	}
	
	padding: 16rpx;
	background-color: #fff;
	border-radius: 4px;
	font-size: 28rpx;
	// color: #666;
	margin-bottom: 20rpx;
	
	image{
		display: block;
		width: 100%;
		// 默认设置一个图片的大约值
		height: 350rpx;
	}
	
	.content{
		margin-top: 20upx;
		
		.money{
			position: absolute;
			margin-left: 70upx;
			// color: #fa3534;
			margin-top: 8rpx;
		}
		.icon{
			border-radius: 50%;
			width: 60upx;
			height: 60upx;
		}
		
		// .label{
		// 	background-color: #fa3534;
		// 	color: #fff;
		// 	font-size: 20rpx;
		// 	padding: 4rpx 16rpx;
		// 	border-radius: 20rpx;
		// }
		
		.shop-name{
			font-size: 20rpx;
			color: #999;
		}
	}
}
</style>
